package model

import (
	"time"

	"github.com/jinzhu/gorm"
)

// User 用户信息结构体
type User struct {
	gorm.Model
	Name     string `gorm:"type:varchar(64);not null;column:name"`
	Password string `gorm:"type:varchar(255);not null;column:password"`
	Email    string `gorm:"type:varchar(255);not null;column:email"`
}

// UserSerializer 序列化结构体
type UserSerializer struct {
	ID        uint       `json:"id"`
	CreatedAt time.Time  `json:"created_at"`
	UpdatedAt time.Time  `json:"updated_at"`
	DeletedAt *time.Time `json:"deleted_at"`
	Name      string     `json:"name"`
	Password  string     `json:"password"`
	Email     string     `json:"email"`
}

// Serializer 返回User json数据
func (u *User) Serializer() UserSerializer {
	return UserSerializer{
		ID:        u.ID,
		CreatedAt: u.CreatedAt,
		UpdatedAt: u.UpdatedAt,
		DeletedAt: u.DeletedAt,
		Name:      u.Name,
		Password:  u.Password,
		Email:     u.Email,
	}
}
